<span th:each="id,stat:${ids}" xmlns:th="http://www.w3.org/1999/xhtml">
    <span th:if="${not stat.last}" th:text="${id} + ','"></span>
    <span th:if="${stat.last}" th:text="${id}"></span>
</span>